<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="5. Using the EJScreen API via EJAM">
<title>Using the EJScreen API via EJAM • EJAM</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet">
<script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><!-- Font Awesome icons --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/v4-shims.min.css" integrity="sha256-wZjR52fzng1pJHwx4aV2AO3yyTOXrcDW7jBpJtTwVxw=" crossorigin="anonymous">
<!-- bootstrap-toc --><script src="https://cdn.jsdelivr.net/gh/afeld/bootstrap-toc@v1.0.1/dist/bootstrap-toc.min.js" integrity="sha256-4veVQbu7//Lk5TSmc7YV48MxtMy98e26cf5MrgZYnwo=" crossorigin="anonymous"></script><!-- headroom.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/headroom.min.js" integrity="sha256-AsUX4SJE1+yuDu5+mAVzJbuYNPHj/WroHuZ8Ir/CkE0=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/headroom/0.11.0/jQuery.headroom.min.js" integrity="sha256-ZX/yNShbjqsohH1k95liqY9Gd8uOiE1S4vZc+9KQ1K4=" crossorigin="anonymous"></script><!-- clipboard.js --><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.11/clipboard.min.js" integrity="sha512-7O5pXpc0oCRrxk8RUfDYFgn0nO1t+jLuIOQdOMRp4APB7uZ4vSjspzp5y6YDtDs4VzUSTbWzBFZ/LKJhnyFOKw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script><!-- search --><script src="https://cdnjs.cloudflare.com/ajax/libs/fuse.js/6.4.6/fuse.js" integrity="sha512-zv6Ywkjyktsohkbp9bb45V6tEMoWhzFzXis+LrMehmJZZSys19Yxf1dopHx7WzIKxr5tK2dVcYmaCk2uqdjF4A==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/autocomplete.js/0.38.0/autocomplete.jquery.min.js" integrity="sha512-GU9ayf+66Xx2TmpxqJpliWbT5PiGYxpaG8rfnBEk1LL8l1KGkRShhngwdXK1UgqhAzWpZHSiYPc09/NwDQIGyg==" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mark.js/8.11.1/mark.min.js" integrity="sha512-5CYOlHXGh6QpOFA/TeTylKLWfB3ftPsde7AnmhuitiTX4K5SqCLBeKro6sPS8ilsz1Q4NRx3v8Ko2IBiszzdww==" crossorigin="anonymous"></script><!-- pkgdown --><script src="../pkgdown.js"></script><meta property="og:title" content="Using the EJScreen API via EJAM">
<meta property="og:description" content="5. Using the EJScreen API via EJAM">
<meta property="og:image" content="usepa.github.io/EJAM/logo.svg">
<!-- mathjax --><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js" integrity="sha256-nvJJv9wWKEm88qvoQl9ekL2J+k/RWIsaSScxxlsrv8k=" crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/config/TeX-AMS-MML_HTMLorMML.js" integrity="sha256-84DKXVJXs0/F8OTMzX4UR909+jtl4G7SPypPavF+GfA=" crossorigin="anonymous"></script><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>
    

    <nav class="navbar fixed-top navbar-light navbar-expand-lg bg-light" data-bs-theme="light"><div class="container">
    
    <a class="navbar-brand me-2" href="../index.html">EJAM</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">2.2.2</small>

    
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto">
<li class="nav-item">
  <a class="nav-link" href="../reference/index.html">Reference</a>
</li>
<li class="active nav-item dropdown">
  <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" id="dropdown-articles">Articles</a>
  <div class="dropdown-menu" aria-labelledby="dropdown-articles">
    <h6 class="dropdown-header" data-toc-skip>Overview for EJAM Users</h6>
    <a class="dropdown-item" href="../articles/0_whatis.html">What is EJAM</a>
    <a class="dropdown-item" href="../articles/0_webapp.html">Using EJAM</a>
    <div class="dropdown-divider"></div>
    <h6 class="dropdown-header" data-toc-skip>For analysts using R</h6>
    <a class="dropdown-item" href="../articles/1_installing.html">Installing the EJAM R package</a>
    <a class="dropdown-item" href="../articles/2_quickstart.html">Quick Start Guide</a>
    <a class="dropdown-item" href="../articles/3_analyzing.html">Basics of Using EJAM for Analysis in RStudio</a>
    <a class="dropdown-item" href="../articles/4_advanced.html">Advanced Features</a>
    <a class="dropdown-item" href="../articles/5_ejscreenapi.html">Using the EJScreen API via EJAM</a>
    <a class="dropdown-item" href="../articles/6_future_plans.html">Future Plans and Ideas for EJAM</a>
  </div>
</li>
<li class="nav-item">
  <a class="nav-link" href="../news/index.html">Changelog</a>
</li>
      </ul>
<form class="form-inline my-2 my-lg-0" role="search">
        <input type="search" class="form-control me-sm-2" aria-label="Toggle navigation" name="search-input" data-search-index="../search.json" id="search-input" placeholder="Search for" autocomplete="off">
</form>

      <ul class="navbar-nav">
<li class="nav-item">
  <a class="external-link nav-link" href="https://github.com/USEPA/EJAM/" aria-label="github">
    <span class="fab fa fab fa-github fa-lg"></span>
     
  </a>
</li>
      </ul>
</div>

    
  </div>
</nav><div class="container template-article">




<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">
      <img src="../logo.svg" class="logo" alt=""><h1>Using the EJScreen API via EJAM</h1>
            
      
      <small class="dont-index">Source: <a href="https://github.com/USEPA/EJAM/blob/HEAD/vignettes/5_ejscreenapi.Rmd" class="external-link"><code>vignettes/5_ejscreenapi.Rmd</code></a></small>
      <div class="d-none name"><code>5_ejscreenapi.Rmd</code></div>
    </div>

    
    
<div class="section level3">
<h3 id="note-these-features-may-still-be-in-development-and-untested-for-use-outside-epas-network-">
<strong>NOTE: These features may still be in development and
untested for use outside EPA’s network.</strong><a class="anchor" aria-label="anchor" href="#note-these-features-may-still-be-in-development-and-untested-for-use-outside-epas-network-"></a>
</h3>
<p>EJAM includes the EJAMejscreen package, a set of functions and data
that facilitate access to EJScreen data and reports, using the API
provided by EJScreen. It does a few things:</p>
<ul>
<li>
<strong>API wrapper:</strong> Makes it easier to use the EJScreen
API from R</li>
<li>
<strong>Batch processor:</strong> Includes a function that lets you
obtain a batch of EJScreen results via API, assembled in a table.</li>
<li>
<strong>Web App:</strong> Provides a shiny R web app interface that
helps you use the batch tool. This provides access to the EJScreen API
in a loop or batch mode. It uses EJScreen to run reports on multiple
places one at a time, so it is somewhat slow for more than a handful of
places, but exactly replicates EJScreen results.</li>
<li>
<strong>Web Module:</strong> EJAM will include a shiny module within
EJAM’s web app UI, that provides access to both in one place.</li>
</ul>
<div class="section level4">
<h4 id="get-one-ejscreen-report-in-your-web-browser">Get one EJScreen report in your web browser<a class="anchor" aria-label="anchor" href="#get-one-ejscreen-report-in-your-web-browser"></a>
</h4>
<p>This works best for one site at a time, and does not provide results
in a table, just a formatted web page EJScreen Community Report directly
from EJScreen.</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span></span>
<span><span class="co"># Browser opens to view one site report</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/browseURL.html" class="external-link">browseURL</a></span><span class="op">(</span></span>
<span>  <span class="fu"><a href="../reference/url_ejscreen_report.html">url_ejscreen_report</a></span><span class="op">(</span></span>
<span>    lon <span class="op">=</span> <span class="op">-</span><span class="fl">92.380556</span>, </span>
<span>    lat <span class="op">=</span> <span class="fl">31.316944</span>, </span>
<span>    radius <span class="op">=</span> <span class="fl">3</span></span>
<span>  <span class="op">)</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Get the URL for each site report</span></span>
<span><span class="fu"><a href="../reference/url_ejscreen_report.html">url_ejscreen_report</a></span><span class="op">(</span></span>
<span>  lon <span class="op">=</span> <span class="va">testpoints_10</span><span class="op">$</span><span class="va">lon</span>, </span>
<span>  lat <span class="op">=</span> <span class="va">testpoints_10</span><span class="op">$</span><span class="va">lat</span>, </span>
<span>  radius <span class="op">=</span> <span class="fl">3</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># Open each webpage in a browser</span></span>
<span><span class="kw">for</span> <span class="op">(</span><span class="va">i</span> <span class="kw">in</span> <span class="fl">1</span><span class="op">:</span><span class="fl">2</span><span class="op">)</span> <span class="op">{</span></span>
<span>  <span class="fu"><a href="https://rdrr.io/r/utils/browseURL.html" class="external-link">browseURL</a></span><span class="op">(</span><span class="fu"><a href="../reference/url_ejscreen_report.html">url_ejscreen_report</a></span><span class="op">(</span></span>
<span>    lon <span class="op">=</span> <span class="va">testpoints_10</span><span class="op">$</span><span class="va">lon</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">2</span><span class="op">]</span>, </span>
<span>    lat <span class="op">=</span> <span class="va">testpoints_10</span><span class="op">$</span><span class="va">lat</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">2</span><span class="op">]</span>, </span>
<span>    radius <span class="op">=</span> <span class="fl">3</span><span class="op">)</span><span class="op">[</span><span class="va">i</span><span class="op">]</span><span class="op">)</span></span>
<span><span class="op">}</span></span></code></pre></div>
</div>
<div class="section level4">
<h4 id="get-ejscreen-results-tables-in-rstudio-in-tables-for-a-list-of-sites">Get EJScreen results tables in RStudio (in tables, for a list of
sites)<a class="anchor" aria-label="anchor" href="#get-ejscreen-results-tables-in-rstudio-in-tables-for-a-list-of-sites"></a>
</h4>
<p>In RStudio, you can use EJAM’s EJScreen API code like this:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span></span>
<span><span class="co"># To interactively pick your own spreadsheet file from your local drive, </span></span>
<span><span class="co"># that has lat and lon as two column headings and then one row per site:</span></span>
<span></span>
<span><span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/EJAMejscreenapi/man/ejscreenit.html" class="external-link">ejscreenit</a></span><span class="op">(</span>radius <span class="op">=</span> <span class="fl">1</span><span class="op">)</span> <span class="co"># will prompt you for excel file with lat lon in it</span></span></code></pre></div>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">x</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/EJAMejscreenapi/man/ejscreenit.html" class="external-link">ejscreenit</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/data.frame.html" class="external-link">data.frame</a></span><span class="op">(</span>lon <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="op">-</span><span class="fl">111</span>,<span class="op">-</span><span class="fl">113</span><span class="op">)</span>, lat <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="fl">41</span>,<span class="fl">43</span><span class="op">)</span><span class="op">)</span>, radius <span class="op">=</span> <span class="fl">2</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/base/names.html" class="external-link">names</a></span><span class="op">(</span><span class="va">x</span><span class="op">)</span></span>
<span><span class="va">x</span><span class="op">$</span><span class="va">map</span></span>
<span><span class="va">x</span><span class="op">$</span><span class="va">table</span></span>
<span><span class="co"># ejscreenit_see_table(x) </span></span></code></pre></div>
</div>
<div class="section level4">
<h4 id="get-ejscreen-results-tables-in-a-local-web-app-not-tested">Get EJScreen results tables in a local web app ***not tested<a class="anchor" aria-label="anchor" href="#get-ejscreen-results-tables-in-a-local-web-app-not-tested"></a>
</h4>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">### *** NOT TESTED - MAY NO LONGER WORK AS SHIFT TO USING MODULE VERSION</span></span>
<span><span class="co"># If you have the local source package EJAMejscreenapi you can do this:</span></span>
<span><span class="co"># setwd("YOUR PATH GOES HERE  EJAMejscreenapi")</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/USEPA/EJAMejscreenapi" class="external-link">EJAMejscreenapi</a></span><span class="op">)</span></span>
<span><span class="fu">EJAMejscreenapi</span><span class="fu">::</span><span class="fu">run_app</span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level4">
<h4 id="get-ejscreen-results-tables-in-a-local-web-app-module-not-tested">Get EJScreen results tables in a local web app module ***not
tested<a class="anchor" aria-label="anchor" href="#get-ejscreen-results-tables-in-a-local-web-app-module-not-tested"></a>
</h4>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://github.com/USEPA/EJAMejscreenapi" class="external-link">EJAMejscreenapi</a></span><span class="op">)</span> </span>
<span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://shiny.posit.co/" class="external-link">shiny</a></span><span class="op">)</span>; <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://magrittr.tidyverse.org" class="external-link">magrittr</a></span><span class="op">)</span>; <span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://rstudio.github.io/leaflet/" class="external-link">leaflet</a></span><span class="op">)</span>  </span>
<span><span class="co"># must attach all of those manually for this to work?</span></span>
<span><span class="kw"><a href="https://rdrr.io/r/base/source.html" class="external-link">source</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/system.file.html" class="external-link">system.file</a></span><span class="op">(</span><span class="st">"global.R"</span>, package <span class="op">=</span> <span class="st">"EJAMejscreenapi"</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="va">default_calculate_ratios</span> <span class="op">&lt;-</span> <span class="cn">TRUE</span></span>
<span><span class="va">use_ejscreenit_tf</span> <span class="op">&lt;-</span> <span class="cn">FALSE</span></span>
<span><span class="co">######################### #</span></span>
<span><span class="va">TEST_UI</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">request</span><span class="op">)</span> <span class="op">{</span></span>
<span>  <span class="fu">shiny</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/shiny/man/fluidPage.html" class="external-link">fluidPage</a></span><span class="op">(</span></span>
<span>    <span class="fu"><a href="https://rdrr.io/pkg/shiny/man/tabsetPanel.html" class="external-link">tabsetPanel</a></span><span class="op">(</span></span>
<span>      <span class="fu"><a href="https://rdrr.io/pkg/shiny/man/tabPanel.html" class="external-link">tabPanel</a></span><span class="op">(</span></span>
<span>        title <span class="op">=</span> <span class="st">"api app"</span>,</span>
<span>        <span class="fu">shiny</span><span class="fu">::</span><span class="fu"><a href="https://rstudio.github.io/htmltools/reference/builder.html" class="external-link">h2</a></span><span class="op">(</span><span class="st">'EJScreen API batch tool packaged with EJAM'</span><span class="op">)</span>, </span>
<span>        <span class="co"># EJAM:::mod_ejscreenapi_ui("TESTID", simpleradius_default_for_ui = 2),</span></span>
<span>        <span class="fu">mod_ejscreenapi_ui</span><span class="op">(</span><span class="st">"TESTID"</span>, simpleradius_default_for_ui <span class="op">=</span> <span class="fl">2</span><span class="op">)</span>,</span>
<span>        <span class="fu"><a href="https://rstudio.github.io/htmltools/reference/builder.html" class="external-link">br</a></span><span class="op">(</span><span class="op">)</span></span>
<span>      <span class="op">)</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="op">}</span></span>
<span><span class="co">######################### #</span></span>
<span><span class="va">TEST_SERVER</span> <span class="op">&lt;-</span> <span class="kw">function</span><span class="op">(</span><span class="va">input</span>, <span class="va">output</span>, <span class="va">session</span><span class="op">)</span> <span class="op">{</span></span>
<span>  <span class="co">#x &lt;- EJAM:::mod_ejscreenapi_server(</span></span>
<span>  <span class="va">x</span> <span class="op">&lt;-</span>     <span class="fu">mod_ejscreenapi_server</span><span class="op">(</span></span>
<span>    <span class="st">"TESTID"</span>, </span>
<span>    default_points_shown_at_startup_react <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/shiny/man/reactive.html" class="external-link">reactive</a></span><span class="op">(</span><span class="va">testpoints_5</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">2</span>,<span class="op">]</span><span class="op">)</span>,</span>
<span>    use_ejscreenit <span class="op">=</span> <span class="va">use_ejscreenit_tf</span></span>
<span>  <span class="op">)</span></span>
<span>  <span class="va">output</span><span class="op">$</span><span class="va">testinfo2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/pkg/shiny/man/renderPrint.html" class="external-link">renderText</a></span><span class="op">(</span></span>
<span>    <span class="fu"><a href="https://rdrr.io/r/base/cat.html" class="external-link">cat</a></span><span class="op">(</span><span class="st">"x names:  "</span>, <span class="fu"><a href="https://rdrr.io/r/base/paste.html" class="external-link">paste0</a></span><span class="op">(</span><span class="fu"><a href="https://rdrr.io/r/base/names.html" class="external-link">names</a></span><span class="op">(</span><span class="fu">x</span><span class="op">(</span><span class="op">)</span><span class="op">)</span>, collapse <span class="op">=</span> <span class="st">", "</span><span class="op">)</span>, <span class="st">"\n"</span><span class="op">)</span></span>
<span>  <span class="op">)</span></span>
<span>  <span class="va">output</span><span class="op">$</span><span class="va">results</span> <span class="op">&lt;-</span> <span class="fu">DT</span><span class="fu">::</span><span class="fu"><a href="https://rdrr.io/pkg/DT/man/dataTableOutput.html" class="external-link">renderDT</a></span><span class="op">(</span><span class="op">{</span><span class="fu">x</span><span class="op">(</span><span class="op">)</span><span class="op">}</span>, </span>
<span>                                        options <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/list.html" class="external-link">list</a></span><span class="op">(</span></span>
<span>                                          selection <span class="op">=</span> <span class="st">'multiple'</span>,</span>
<span>                                          dom <span class="op">=</span> <span class="st">'rtip'</span>, <span class="co"># specify 4 DOM elements: </span></span>
<span>                                          <span class="co"># processing, table, info, pagination </span></span>
<span>                                          <span class="co"># per https://datatables.net/examples/basic_init/dom.html</span></span>
<span>                                          scrollX <span class="op">=</span> <span class="cn">TRUE</span>, </span>
<span>                                          searchPanes <span class="op">=</span> <span class="cn">TRUE</span>  <span class="co"># does this work?</span></span>
<span>                                        <span class="op">)</span>,</span>
<span>                                        escape <span class="op">=</span> <span class="cn">FALSE</span> </span>
<span>  <span class="op">)</span></span>
<span>  <span class="co"># *** CAUTION ***</span></span>
<span>  <span class="co"># escape= TRUE is better for security reasons (XSS attacks).</span></span>
<span>  <span class="co"># escape= FALSE lets ejscreen URL links work, </span></span>
<span>  <span class="co">#   but not links from ECHO table download.</span></span>
<span><span class="op">}</span></span>
<span><span class="co">######################### #</span></span>
<span></span>
<span><span class="fu"><a href="https://rdrr.io/pkg/shiny/man/shinyApp.html" class="external-link">shinyApp</a></span><span class="op">(</span>ui <span class="op">=</span> <span class="va">TEST_UI</span>, server <span class="op">=</span> <span class="va">TEST_SERVER</span><span class="op">)</span> <span class="co"># Try module in mini/test app</span></span></code></pre></div>
</div>
</div>
<div class="section level2">
<h2 id="compare-numbers-provided-by-ejam-and-ejscreen-api-comparing-estimated-population-indicator-scores-etc-">Compare numbers provided by EJAM and EJScreen API (comparing
estimated population, indicator scores, etc.)<a class="anchor" aria-label="anchor" href="#compare-numbers-provided-by-ejam-and-ejscreen-api-comparing-estimated-population-indicator-scores-etc-"></a>
</h2>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span></span>
<span><span class="co">################# # </span></span>
<span><span class="co"># Run (potentially long) analysis in EJScreen, </span></span>
<span><span class="co"># Pick sample of randomly selected EPA-regulated facilities in the FRS:</span></span>
<span><span class="co"># n &lt;- 30 # or 1,000 sites, e.g.</span></span>
<span><span class="co"># pts &lt;- testpoints_n(n, weighting = 'frs')</span></span>
<span><span class="co"># radius &lt;- 3</span></span>
<span><span class="co"># (approx 40 minutes for 1,000 points, maybe )</span></span>
<span><span class="co"># and also in EJAM</span></span>
<span><span class="co">## vs &lt;- ejscreen_vs_ejam(pts, radius = radius, include_ejindexes = TRUE)</span></span>
<span><span class="co">################# # </span></span>
<span><span class="co"># or to save time, look at just 500 sites and </span></span>
<span><span class="co"># just 1 mile radius, already run in ejscreenit()</span></span>
<span><span class="co"># About 10-15 seconds in EJAM:</span></span>
<span><span class="va">testoutput_ejamit_500_1miles</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/ejamit.html">ejamit</a></span><span class="op">(</span><span class="va">testpoints_500</span>, radius <span class="op">=</span> <span class="fl">1</span>, </span>
<span>                                         include_ejindexes <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span><span class="co"># setdiff(1:500, testoutput_ejamit_500_1miles$results_bysite$ejam_uniq_id )</span></span>
<span><span class="co"># all.equal(1:500, testoutput_ejscreenit_500$table$sitenumber )</span></span>
<span><span class="va">vs</span> <span class="op">&lt;-</span> <span class="fu">EJAM</span><span class="fu">:::</span><span class="fu"><a href="../reference/ejscreen_vs_ejam_alreadyrun.html">ejscreen_vs_ejam_alreadyrun</a></span><span class="op">(</span></span>
<span>  apisite <span class="op">=</span> <span class="va">testoutput_ejscreenit_500</span><span class="op">$</span><span class="va">table</span>, </span>
<span>  ejamsite <span class="op">=</span> <span class="va">testoutput_ejamit_500_1miles</span><span class="op">$</span><span class="va">results_bysite</span></span>
<span><span class="op">)</span></span>
<span><span class="co">################# # </span></span>
<span></span>
<span><span class="co"># See summary stats on the comparison</span></span>
<span></span>
<span><span class="va">sum_vs</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/ejscreen_vs_ejam_summary.html">ejscreen_vs_ejam_summary</a></span><span class="op">(</span><span class="va">vs</span><span class="op">)</span></span>
<span><span class="va">q</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/ejscreen_vs_ejam_summary_quantiles.html">ejscreen_vs_ejam_summary_quantiles</a></span><span class="op">(</span></span>
<span>  <span class="va">vs</span>, mystat <span class="op">=</span> <span class="st">'ratio'</span>, </span>
<span>  myvars <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">'pop'</span>,  <span class="st">"blockcount_near_site"</span>, <span class="va">names_these</span><span class="op">)</span>, digits <span class="op">=</span> <span class="fl">2</span><span class="op">)</span></span>
<span><span class="va">q</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/order.html" class="external-link">order</a></span><span class="op">(</span><span class="va">q</span><span class="op">[</span>, <span class="st">"95%"</span><span class="op">]</span>, decreasing <span class="op">=</span> <span class="cn">F</span><span class="op">)</span>, <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"50%"</span>, <span class="st">"95%"</span><span class="op">)</span><span class="op">]</span></span>
<span></span>
<span><span class="co">## examine one site closely</span></span>
<span><span class="fu"><a href="../reference/ejscreen_vs_ejam_see1.html">ejscreen_vs_ejam_see1</a></span><span class="op">(</span></span>
<span>  <span class="va">vs</span>, mysite <span class="op">=</span> <span class="fl">1</span>, </span>
<span>  myvars <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">'pop'</span>, <span class="st">"blockcount_near_site"</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/ejscreen_vs_ejam_see1.html">ejscreen_vs_ejam_see1</a></span><span class="op">(</span><span class="va">vs</span>, mysite <span class="op">=</span> <span class="fl">1</span>, </span>
<span>                      myvars <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">'lowlifex'</span>, <span class="st">"Demog.Index.Supp"</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="../reference/ejscreen_vs_ejam_see1map.html">ejscreen_vs_ejam_see1map</a></span><span class="op">(</span><span class="fl">1</span>, x <span class="op">=</span> <span class="va">vs</span><span class="op">)</span></span>
<span></span>
<span></span>
<span><span class="co"># or to see some related info:</span></span>
<span><span class="va">out1</span> <span class="op">=</span> <span class="va">testoutput_ejscreenit_500</span><span class="op">$</span><span class="va">table</span></span>
<span><span class="va">out1</span> <span class="op">=</span> <span class="va">out1</span><span class="op">[</span><span class="op">!</span><span class="fu"><a href="https://rdrr.io/r/base/NA.html" class="external-link">is.na</a></span><span class="op">(</span><span class="va">out1</span><span class="op">$</span><span class="va">pm</span><span class="op">)</span>, <span class="op">]</span></span>
<span><span class="va">out1</span><span class="op">$</span><span class="va">id</span> <span class="op">=</span> <span class="fl">1</span><span class="op">:</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">NROW</a></span><span class="op">(</span><span class="va">out1</span><span class="op">)</span></span>
<span><span class="va">ejamsite</span> <span class="op">=</span> <span class="fu"><a href="../reference/ejamit.html">ejamit</a></span><span class="op">(</span></span>
<span>  sitepoints <span class="op">=</span> <span class="va">out1</span><span class="op">[</span> , <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"lat"</span>, <span class="st">"lon"</span><span class="op">)</span><span class="op">]</span>, radius <span class="op">=</span> <span class="fl">1</span><span class="op">)</span><span class="op">$</span><span class="va">results_bysite</span></span>
<span><span class="va">ejamsite</span><span class="op">$</span><span class="va">id</span> <span class="op">&lt;-</span> <span class="va">ejamsite</span><span class="op">$</span><span class="va">ejam_uniq_id</span></span>
<span><span class="va">missingdatarows</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/sets.html" class="external-link">setdiff</a></span><span class="op">(</span><span class="fl">1</span><span class="op">:</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">NROW</a></span><span class="op">(</span><span class="va">out1</span><span class="op">)</span>, <span class="va">ejamsite</span><span class="op">$</span><span class="va">ejam_uniq_id</span><span class="op">)</span></span>
<span><span class="va">out1</span> <span class="op">&lt;-</span> <span class="va">out1</span><span class="op">[</span><span class="op">!</span><span class="op">(</span><span class="fl">1</span><span class="op">:</span><span class="fu"><a href="https://rdrr.io/r/base/nrow.html" class="external-link">NROW</a></span><span class="op">(</span><span class="va">out1</span><span class="op">)</span> <span class="op"><a href="https://rdrr.io/r/base/match.html" class="external-link">%in%</a></span> <span class="va">missingdatarows</span><span class="op">)</span>, <span class="op">]</span></span></code></pre></div>
</div>
<div class="section level2">
<h2 id="compare-speeds-for-ejam-and-ejscreen-api">Compare Speeds for EJAM and EJScreen API<a class="anchor" aria-label="anchor" href="#compare-speeds-for-ejam-and-ejscreen-api"></a>
</h2>
<p>EJAM is designed to provide results for large numbers of sites very
quickly, so it can analyze well over 100,000 sites per hour, and can
analyze 1,000 sites in something like 10 to 20 seconds (assuming it has
already been initialized with loaded data and indexing, which needs to
be done once up front and can take a minute). Using the EJScreen API by
contrast as of early 2024 took well over 100 times as long.</p>
<p>There are some (internal / not necessarily all exported) EJAM and
EJAMejscreenapi functions:</p>
<ul>
<li><p>speedreport</p></li>
<li><p>speedmessage</p></li>
<li><p>speedtest</p></li>
<li><p>speedtest_plot</p></li>
<li><p>speedtable_summarize</p></li>
<li><p>speedtable_expand</p></li>
</ul>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">began</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/Sys.time.html" class="external-link">Sys.time</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="va">x</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/pkg/EJAMejscreenapi/man/ejscreenit.html" class="external-link">ejscreenit</a></span><span class="op">(</span><span class="va">testpoints_10</span>, radius <span class="op">=</span> <span class="fl">3.1</span><span class="op">)</span></span>
<span><span class="va">ended</span> <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/Sys.time.html" class="external-link">Sys.time</a></span><span class="op">(</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/pkg/EJAMejscreenapi/man/speedreport.html" class="external-link">speedreport</a></span><span class="op">(</span>start <span class="op">=</span> <span class="va">began</span>, end <span class="op">=</span> <span class="va">ended</span>, n <span class="op">=</span> <span class="fl">10</span><span class="op">)</span></span>
<span><span class="co"># ...... </span></span>
<span><span class="co"># Rate of 768 buffers per hour: 10 lat/long pairs took 47 seconds</span></span>
<span><span class="co">## Sometimes 330 per hour.</span></span></code></pre></div>
<div class="sourceCode" id="cb8"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># speeds &lt;- EJAM:::speedtest(n = 100, radii = c(1,3,5,6.2,10), honk_when_ready = FALSE)</span></span>
<span><span class="co"># speeds[order(speeds$points, speeds$miles), ]</span></span>
<span><span class="co">## Rate of &gt; 100,000 buffers per hour for radius &lt; 10 miles</span></span>
<span><span class="co">## EJAM's ejamit() can be 100x to &gt;300x times as fast as ejscreenit()</span></span></code></pre></div>
<p><img src="plot_speed_vs_radius.png" style="width:6in"></p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co">## ejamit() just combines getblocksnearby() and doaggregate()</span></span>
<span><span class="va">sitepoints</span> <span class="op">&lt;-</span> <span class="va">testpoints_1000</span></span>
<span><span class="va">radius</span> <span class="op">&lt;-</span> <span class="fl">1</span></span>
<span><span class="co"># elapsed &lt;- system.time({</span></span>
<span><span class="co"># began = Sys.time()</span></span>
<span><span class="va">out2</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/ejamit.html">ejamit</a></span><span class="op">(</span></span>
<span>  sitepoints <span class="op">=</span>  <span class="va">sitepoints</span>,</span>
<span>  radius <span class="op">=</span> <span class="va">radius</span></span>
<span><span class="op">)</span></span>
<span><span class="co"># EJAM:::speedreport(began, Sys.time(), n = NROW(sitepoints))</span></span>
<span><span class="co"># })</span></span>
<span><span class="co"># print(elapsed)</span></span></code></pre></div>
</div>
  </main><aside class="col-md-3"><nav id="toc"><h2>On this page</h2>
    </nav></aside>
</div>



    <footer><div class="pkgdown-footer-left">
  <p>DRAFT/beta</p>
</div>

<div class="pkgdown-footer-right">
  <p>EJAM Version 2.2.2 beta</p>
</div>

    </footer>
</div>

  

  

  </body>
</html>
